import { createApp } from 'vue'
import Dialog from '@/components/dialog/Dialog.vue'

const createDialog = (message: string, option = {}) => {
  const mountNode = document.createElement('div')
  const instance = createApp(Dialog, {
    show: true,
    message,
    ...option
  })

  document.body.appendChild(mountNode)
  instance.mount(mountNode)

  // console.log('dialog instance:', instance)

  // TODO 弹框显示时间暂时写死
  setTimeout(() => {
    // @ts-ignore
    instance.unmount(mountNode)
    document.body.removeChild(mountNode)
  }, 3000)
}

export default createDialog
